package com.example.pojo;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import sun.plugin.com.Utils;

/**
* <p>
* 员工表
* </p>
* @author wsl
* @since 2022-04-11
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ApiModel(value = "Emp对象", description = "员工表")
public class Emp implements Serializable, UserDetails {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("员工编号")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("员工姓名")
    private String empName;

    @ApiModelProperty("简历编号")
    private Integer resumeId;

    @ApiModelProperty("部门编号")
    private Integer deptId;

    @ApiModelProperty("职称编号")
    private Integer rankId;

    @ApiModelProperty("职位编号")
    private Integer positionId;

    @ApiModelProperty("员工工号")
    private String workId;

    @ApiModelProperty("在职状态")
    private Integer status;

    @ApiModelProperty("上级编号")
    private Integer superiorId;

    @ApiModelProperty("员工联系电话")
    private String phone;

    @ApiModelProperty("聘用形式")
    @TableField(exist = false)
    private Integer hireForm;

    @ApiModelProperty("入职日期")
    @TableField(fill = FieldFill.INSERT)
    private LocalDate hireDate;

    @ApiModelProperty("密码")
    private String password;

    @ApiModelProperty("是否在线")
    private String online;

    @ApiModelProperty("员工头像编号")
    private Integer photoId;

    @ApiModelProperty("用户头像")
    @TableField(exist = false)
    private String photo;

    @ApiModelProperty("用户名称")
    private String nickname;

    @ApiModelProperty("修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    @TableField(fill = FieldFill.UPDATE)
    private LocalDateTime updateTime;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @ApiModelProperty("是否删除")
    private Integer deleted;

    @ApiModelProperty("部门")
    @TableField(exist = false)
    private Dept dept;

    @ApiModelProperty("员工简历")
    @TableField(exist = false)
    private Resume resume;

    @ApiModelProperty("上级员工")
    @TableField(exist = false)
    private Emp superior;

//    @ApiModelProperty("职称")
//    @TableField(exist = false)
//    private Rank

    @ApiModelProperty("职位")
    @TableField(exist = false)
    private Position position;

    @ApiModelProperty("角色列表")
    @TableField(exist = false)
    private List<Role> roles;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(roles!=null && roles.size()!=0){
            return roles.stream()
                    .map(role -> new SimpleGrantedAuthority(role.getRoleNameCh()))
                    .collect(Collectors.toList());
        }
        return null;
    }

    @Override
    public String getUsername() {
        return this.empName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
